<template>
    <div>
        <el-dialog
                :title="title"
                :visible.sync="dialogVisible"
                width="50%"
                :show-close="true"
                :close-on-click-modal="false"
                v-dialogDrag
        >
            <el-form :model="model" :rules="rule" ref="registerRef" label-width="100px">
                <el-row>
                                                <el-col :span="12">
                                <el-form-item label="账号" prop="account">
                                        <el-input v-model.trim="model.account"
                                                  placeholder="请输入账号"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="密码" prop="password">
                                        <el-input v-model.trim="model.password"
                                                  placeholder="请输入密码"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="性别" prop="sex">
                                        <el-input v-model.trim="model.sex"
                                                  placeholder="请输入性别"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="角色ID" prop="roleId">
                                        <el-input v-model.trim="model.roleId"
                                                  placeholder="请输入角色ID"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="组织ID" prop="deptId">
                                        <el-input v-model.trim="model.deptId"
                                                  placeholder="请输入组织ID"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="账号名称" prop="name">
                                        <el-input v-model.trim="model.name"
                                                  placeholder="请输入账号名称"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="手机号" prop="phone">
                                        <el-input v-model.trim="model.phone"
                                                  placeholder="请输入手机号"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="创建人ID" prop="creatorId">
                                        <el-input v-model.trim="model.creatorId"
                                                  placeholder="请输入创建人ID"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="修改人ID" prop="updateId">
                                        <el-input v-model.trim="model.updateId"
                                                  placeholder="请输入修改人ID"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="创建时间" prop="createTime">
                                        <el-date-picker
                                                v-model.trim="model.createTime"
                                                type="date"
                                                placeholder="选择创建时间日期">
                                        </el-date-picker>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="修改时间" prop="updateTime">
                                        <el-date-picker
                                                v-model.trim="model.updateTime"
                                                type="date"
                                                placeholder="选择修改时间日期">
                                        </el-date-picker>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="删除标志（0代表存在 1代表删除）" prop="isDelete">
                                        <el-input v-model.trim="model.isDelete"
                                                  placeholder="请输入删除标志（0代表存在 1代表删除）"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="用户状态" prop="status">
                                        <el-input v-model.trim="model.status"
                                                  placeholder="请输入用户状态"></el-input>
                                </el-form-item>
                            </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible=false">取 消</el-button>
                <el-button type="primary" @click="submitForm('registerRef')">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import {baseurl} from "@/api/api"
    import {httpAction} from "@/api/manage"

    export default {
        name: "userSave",
        data() {
            return {
                model: {},
                disableSubmit: false,
                dialogVisible: false,
                url: {
                    add: this.$api.baseurl + '/user/insert',
                    edit: this.$api.baseurl + '/user/update'
                },
                title: '',
                rule: {
            id:
            {
                required:true, message
            :
                "请填写用户id", trigger
            :
                'blur'
            }
            ,            account:
            {
                required:true, message
            :
                "请填写账号", trigger
            :
                'blur'
            }
            ,            password:
            {
                required:true, message
            :
                "请填写密码", trigger
            :
                'blur'
            }
            ,            sex:
            {
                required:true, message
            :
                "请填写性别", trigger
            :
                'blur'
            }
            ,            roleId:
            {
                required:true, message
            :
                "请填写角色ID", trigger
            :
                'blur'
            }
            ,            deptId:
            {
                required:true, message
            :
                "请填写组织ID", trigger
            :
                'blur'
            }
            ,            name:
            {
                required:true, message
            :
                "请填写账号名称", trigger
            :
                'blur'
            }
            ,            phone:
            {
                required:true, message
            :
                "请填写手机号", trigger
            :
                'blur'
            }
            ,            creatorId:
            {
                required:true, message
            :
                "请填写创建人ID", trigger
            :
                'blur'
            }
            ,            updateId:
            {
                required:true, message
            :
                "请填写修改人ID", trigger
            :
                'blur'
            }
            ,            createTime:
            {
                required:true, message
            :
                "请填写创建时间", trigger
            :
                'blur'
            }
            ,            updateTime:
            {
                required:true, message
            :
                "请填写修改时间", trigger
            :
                'blur'
            }
            ,            isDelete:
            {
                required:true, message
            :
                "请填写删除标志（0代表存在 1代表删除）", trigger
            :
                'blur'
            }
            ,            status:
            {
                required:true, message
            :
                "请填写用户状态", trigger
            :
                'blur'
            }
            
        },
        }
        },
        mounted() {

        },
        methods: {
            add() {
                this.edit({})
            },
            edit(record) {
                if (this.$refs['registerRef'] !== undefined) {
                    this.$refs['registerRef'].resetFields();
                }
                this.model = Object.assign({}, record);
                this.dialogVisible = true;
            },
            submitForm(formName) {
                const that = this;
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        let httpurl = '';
                        if (!this.model.id) {
                            httpurl += this.url.add;
                        } else {
                            httpurl += this.url.edit;
                        }
                        httpAction(httpurl, this.model).then((res) => {
                            if (res.data.code == 200) {
                                that.$message.success("操作成功");
                                that.$emit('ok');
                                this.dialogVisible = false
                            } else {
                                that.$message.warning("操作失败");
                            }
                        })
                    }

                })
            }
        }
    }
</script>

<style scoped>

</style>
